<?php

namespace backend\controllers;

use Yii;
use backend\models\PayTrade;
use backend\models\PayTradeSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\ForbiddenHttpException;
use liangzoe\mobilesmser\TextSmser;
use common\models\SmsLogRecord;
use common\models\UserInfo;
use backend\models\PayUserDiscount;
use backend\models\CustomTrade;
use backend\models\AdminInfo;
use liangzoe\payment\weixin;
use liangzoe\payment\offline;
use backend\models\LogPay;
use backend\models\Image;
use yii\grid\GridView;
use backend\models\PayLogisticsSearch;
use yii\helpers\Html;
/**
 * Base
 * @author suiyue
 *
 */
class BaseController extends Controller
{
	/**
	 * (non-PHPdoc)行为
	 * @see \yii\base\Component::behaviors()
	 */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * (non-PHPdoc)前置函数
     * @see \yii\web\Controller::beforeAction()
     */
    public function beforeOp($op,$access)
    {
    	if(Yii::$app->user->isGuest){			    //登录状态识别
    		return $this->redirect(['/site/login']);
    	}else{
    		if(\Yii::$app->user->can($op) ){  
    			if($access){
    				return $access;
    			}else{
    				throw new ForbiddenHttpException(Yii::t('app','Sorry , You don\'t have permission'));
    			}
    		}else{
    			throw new ForbiddenHttpException(Yii::t('app','Sorry , You don\'t have permission'));
    		}
    	}	  	
    }
    /**
     * 验证操作
     * @param   $action_list 可操作的列表
     * @param   $action    action
     * @return boolean 返回是否有操作权限
     */
    function checkAccess($action_list,$action){
    	if(in_array($action, $action_list)){
    		return true;
    	}else{
    			return false;
    	}
    }
    
}
